<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Form</title>
    <style>
        .warn{color: red}
    </style>
</head>
<body>
<!--/*@thymesVar id="user" type="com.duohe.demo.entity.User"*/-->
<form th:action="@{/test}" th:object="${user}" method="post">
    <div>
        <div>
            <span>姓名</span>
            <span><input type="text" th:field="*{name}" /></span>
            <span class="warn" th:if="${#fields.hasErrors('name')}" th:errors="*{name}">
                名字错误
            </span>
        </div>
        <div>
            <span>年龄</span>
            <span><input type="number" th:field="*{age}" /></span>
            <span class="warn" th:if="${#fields.hasErrors('age')}" th:errors="*{age}">年龄错误</span>
        </div>
        <div>
            <span>邮箱</span>
            <span><input type="text" th:field="*{email}" /></span>
            <span class="warn" th:if="${#fields.hasErrors('email')}" th:errors="*{email}">
                邮箱输入错误
            </span>
        </div>
        <div>
            <span>验证答案</span>
            <span><input type="text" th:field="*{answer}" /></span>
            <span class="warn" th:if="${#fields.hasErrors('answer')}" th:errors="*{answer}">
                答案错误
            </span>
        </div>
        <div>
            <span>
                <button type="submit">提交</button>
            </span>
        </div>
    </div>

</form>

</body>
</html>